/**
 * 
 * @param {string} type get/post
 * @param {string} url 服务器地址
 * @param {*} isAsyn 是否异步
 * @param {string} params 请求参数
 * @param {fn} return 接受相应的回调函数
 */
function ajaxFun(type, url, isAsyn, params){
    let xhr=new XMLHttpRequest();
    type.toLowerCase();
    if(type=="get"){
        if(params!=''){
            let urlParams=url;
            urlParams+="?"+data;
        }
        xhr.open(get,urlParams,isAsyn,data);
        xhr.send();
    }else if(type=="post"){
        xhr.open();
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xhr.send(data);
    }else{
        console.log("类型错误")
    }
    let p=new Prommise(function(resolve,reject){
        xhr.onreadystatechange = function() {
            if (xhr.readyState == 4 && xhr.status == 200) {
                resolve(xhr.responseText);
            } else if (xhr.readyState == 4) {
                reject();
            }
        }
    });
    return p;
}
//调用

    ajaxFun("GET", "1promiseAjax", true, "name=laowang&pwd=666").then(function(resText) {
        console.log(resText);
    }).catch(function() {//失败用catch
        console.log("达咩");
    });
